package com.py.credit.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.py.credit.common.ServiceException;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.ResourceEnterpriseFieldsEnum;
import com.py.credit.service.EnterpriseFamilyService;
import com.py.credit.service.RemoteBaseService;
import com.py.credit.utils.FileUtils;
import com.py.credit.utils.MapCache;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 异议处理controller
 */
@RestController
@RequestMapping(value = "/enterpriseFamily")
public class EnterpriseFamilyController {

	private final static String FRONT_TABLE_ID = "enterpriseFamily";

	@Autowired
	private EnterpriseFamilyService enterpriseFamilyService;

	@Autowired
	private RemoteBaseService remoteBaseService;

	@Value("${absolutepath}")
	private String absolutepath;

	@RequestMapping(value = "/getChart.json")
	public RestServiceResult<Map> getChart(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<Map> result = new RestServiceResult<Map>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getChart(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/getBaseIngfo.json")
	public RestServiceResult<Map> getBaseIngfo(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<Map> result = new RestServiceResult<Map>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getBaseIngfo(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	/**
	 * @api {get} /dataClean/getTableList.json 获取表规则列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 表规则管理
	 * 
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
	 * 
	 */
	@RequestMapping(value = "/selectAll.json")
	public RestServiceResult<List<Map>> selectAll(String mainType, String list, String batchId) {
		RestServiceResult<List<Map>> result = new RestServiceResult<>();

		try {
			List<String> listSelected = new ArrayList<>();
			if (!StringUtils.isBlank(list)) {
				listSelected = Arrays.asList(list.split(","));
			}
			List<Map> tableList = enterpriseFamilyService.selectAll(mainType, listSelected, batchId);
			result.setData(tableList);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常！");
		}
		return result;

	}

	
	@RequestMapping(value = "/selectTybmByLimit.json")
	public RestServiceResult<List<String>> selectTybmByLimit(String mainType, String start, String size,
			HttpServletRequest request) {
		RestServiceResult<List<String>> result = new RestServiceResult<List<String>>();
		try {
			List<String> tableList = enterpriseFamilyService.selectTybmByLimit(mainType, Integer.parseInt(start), Integer.parseInt(size));
			result.setData(tableList);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常！");
		}
		return result;

	}
	
	@RequestMapping(value = "/selectCountAll.json")
	public RestServiceResult<Long> selectCountAll(String mainType) {
		RestServiceResult<Long> result = new RestServiceResult<>();
		try {
			Long count = enterpriseFamilyService.selectCountAll(mainType);
			result.setData(count);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常！");
		}
		return result;

	}

	/**
	 * @api {get} /dataClean/getTableList.json 获取表规则列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 表规则管理
	 * 
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
	 * 
	 */
	@RequestMapping(value = "/autoScoreByIndexSql.json")
	public RestServiceResult<List<Map>> selectAllValuesBySql(String sql, String mainType, String selectedList,
			String batchId, HttpServletRequest request) {
		RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();
		try {
			List<String> l = new ArrayList<String>();
			if (!StringUtils.isBlank(selectedList)) {
				l = Arrays.asList(selectedList.split(","));
			}
			List<Map> list = enterpriseFamilyService.autoScoreByIndexSql(mainType, sql, l, batchId);
			result.setData(list);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常！");
		}
		return result;

	}

	/**
	 * @api {get} /dataClean/getTableList.json 获取表规则列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 表规则管理
	 * 
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
	 * 
	 */
	@RequestMapping(value = "/getTableList.json")
	public RestServiceResult<List<Map>> getTableList(
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, String mainType,
			Page page, HttpServletRequest request) {
		RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementCountController#getAchievementCount", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
		String[] additionalColumns = { "tybm" };
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceEnterpriseFieldsEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		// condition="[{columnEN:\"batch_id\",value:\"EX-test-1-20180326-1174\",type:\"varchar\",fuzzy:fasle}]";
		try {
			List<Map> tableList = enterpriseFamilyService.selectByConditionForPage(showColumns, additionalColumns,
					condition, page, mainType);
			result = new RestServiceResult<List<Map>>(page.getTotalCount(), tableList);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常！");
		}
		return result;

	}

	/**
	 * 获取初始化列
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getOptionalColums.json")
	public RestServiceResult<List<OptionalColumn>> getOptionalColums() {
		RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
		try {
			r = new RestServiceResult<>(ResourceEnterpriseFieldsEnum.getOptionalColumns());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("系统异常");
		}
		return r;

	}

	@RequestMapping(value = "/getLicense.json")
	public RestServiceResult<List<Map>> getLicense(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getLicense(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/getPunish.json")
	public RestServiceResult<List<Map>> getPunish(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getPunish(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/getHighManager.json")
	public RestServiceResult<List<String>> getHighManager(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<List<String>> result = new RestServiceResult<List<String>>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getHighManager(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/getBranch.json")
	public RestServiceResult<List<String>> getBranch(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<List<String>> result = new RestServiceResult<List<String>>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getBranch(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/getHolder.json")
	public RestServiceResult<List<String>> getHolder(String A000001, String A000002, HttpServletRequest request) {
		RestServiceResult<List<String>> result = new RestServiceResult<List<String>>();

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
				return result;
			}
			result.setData(enterpriseFamilyService.getHolder(A000001, A000002));
			return result;
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;

		}
	}

	@RequestMapping(value = "/doFile.json")
	@ApiOperation(value = "查看得分明细", httpMethod = "POST", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "file", name = "file", value = "上传文件", required = true)

	})

	public RestServiceResult<String> doFile(@RequestParam(value = "file") CommonsMultipartFile file,
			@RequestParam(value = "mainType", required = false) String mainType, HttpServletRequest request) {
		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
			try {
				String batchId = enterpriseFamilyService.doUploadFile(file, userInfo, absolutepath, mainType);
				result.setData(batchId);
			} catch (ServiceException e) {
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		return result;

	}

	@IgnoreAuthority
	@RequestMapping("/downloadTemplate.json")
	public void downloadTemplate(HttpServletResponse response,
			@RequestParam(value = "mainType", required = true) String mainType) throws IOException {
		String fileName = "";
		if ("100000".equals(mainType)) {
			fileName = "导入生成报告企业.xlsx";
		} else if ("100001".equals(mainType)) {
			fileName = "导入生成报告自然人.xlsx";
		} else if ("100002".equals(mainType)) {
			fileName = "导入生成报告非企业法人.xlsx";
		}
		FileUtils.downloadFile(this.getClass().getResource("/" + fileName).getPath(), response);

	}

	/**
	 * @api {get} /modelTest/getTableList.json 获取批次列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 表规则管理
	 * 
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
	 * 
	 */
	@RequestMapping(value = "/getBatchExportTableList.json")
	public RestServiceResult<List<Map<String, Object>>> getBatchExportTableList(
			@RequestParam(value = "condition", required = false) String condition,
			@RequestParam(value = "batchId", required = true) String batchId,
			@RequestParam(value = "mainType", required = true) String mainType, Page page, HttpServletRequest request) {

		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceEnterpriseFieldsEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		// condition="[{columnEN:\"batch_id\",value:\"EX-test-1-20180326-1174\",type:\"varchar\",fuzzy:fasle}]";
		RestServiceResult<List<Map<String, Object>>> r = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> list = enterpriseFamilyService.selectBatchExportForPage(showColumns, null,
					condition, page, batchId, mainType);
			if (!CollectionUtils.isEmpty(list)) {
				Set<Integer> userIds = new HashSet<Integer>(list.size());
				for (Map<String, Object> m : list) {
					if (null != m && m.containsKey("cjr") && null != m.get("cjr")) {
						userIds.add(Integer.parseInt(String.valueOf(m.get("cjr"))));
					}
				}
				remoteBaseService.matchUserName(list, result, token, userIds, "cjr", "cjrName");
			}
			r = new RestServiceResult<List<Map<String, Object>>>(page.getTotalCount(), list);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("系统异常！");
		}
		return r;
	}

	/**
	 * 获取批次初始化列
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getBatchExportOptionalColums.json")
	public RestServiceResult<List<OptionalColumn>> getBatchExportOptionalColums() {
		RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
		try {
			r = new RestServiceResult<List<OptionalColumn>>(ResourceEnterpriseFieldsEnum.getOptionalColumns());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("系统异常");
		}
		return r;
	}

	/**
	 * @api {get} /modelTest/getTableList.json 获取批次列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 表规则管理
	 * 
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"rule_package":"1222","rule_desc":"122222","rule_name":"1","rule_method":"123","id":22,"time":"2018-04-23","managerName":"超级管理员"},{"rule_package":"555","rule_desc":"5555","rule_name":"555","rule_method":"555","id":35,"time":"2018-04-26","managerName":"超级管理员"}]}
	 * 
	 */
	@RequestMapping(value = "/getCountSum.json")
	public RestServiceResult<Map<String, Object>> getCountSum(
			@RequestParam(value = "batchId", required = true) String batchId,
			@RequestParam(value = "mainType", required = true) String mainType, Page page, HttpServletRequest request) {

		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<Map<String, Object>> result = new RestServiceResult<Map<String, Object>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		RestServiceResult<Map<String, Object>> r = new RestServiceResult<Map<String, Object>>();
		try {
			int noRepeatCount = enterpriseFamilyService.selectNoRepeatCount(mainType, batchId);
			int rightAllCount = enterpriseFamilyService.selectRightAllCount(mainType, batchId);
			int errorCount = enterpriseFamilyService.selectErrorCount(mainType, batchId);
			Map m = new HashMap();
			m.put("noRepeatCount", noRepeatCount);
			m.put("repeatCount", rightAllCount - noRepeatCount);
			m.put("rightAllCount", rightAllCount);
			m.put("errorCount", errorCount);
			r.setData(m);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("系统异常！");
		}
		return r;
	}

	@RequestMapping(value = "/selectBatchExport.json")
	public RestServiceResult<List<String>> selectBatchExport(String mainType, String batchId,
			HttpServletRequest request) {
		RestServiceResult<List<String>> result = new RestServiceResult<List<String>>();
		result.setData(enterpriseFamilyService.selectBatchExport(mainType, batchId));
		return result;
	}

}